package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Working;
import service.WorkingService;

public class SaveServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");

		response.setContentType("text/html;charset=utf-8");

		PrintWriter out = response.getWriter();

		WorkingService service = new WorkingService();


		String content=request.getParameter("content");
		String title=request.getParameter("title");
		int type=Integer.valueOf(request.getParameter("type"));

		int result = service.save(content,title,type);

		if (result>0) {
			out.print("<script>alert('添加成功');location.href='listServlet?currPageNo=1&pageSize=5';</script>");
		} else {
			out.print("<script>alert('添加失败');history.back();</script>");
		}
	}
}
